<template>
	<view class="contain">
		<view class="title">
			{{info.title}}
		</view>
		<view class="pubisher">
			发布人&emsp;：{{info.publisher}}
		</view>
		<view class="pubisher">
			发布日期：{{info.datetime.slice(0,19).replace("T"," ")}}
		</view>
		<view class="button">
			<button type="default" size="mini" @click="edit()">编辑</button>
		</view>
		<scroll-view class="content" scroll-y="true">
			<u-parse :content="info.content">
			</u-parse>
		</scroll-view>
	</view>
</template>

<script>
	import api from '@/api/index.js'; // 引入api

	export default {
		data() {
			return {
				id: "",
				info: {
					title: "",
					content: "",
					datetime: "",
					publisher: ""
				}
			}
		},
		methods: {
			edit() {
				uni.navigateTo({
					url: `editor/editor?id=${this.id}`
				})
			}
		},
		onLoad(options) {
			// console.log(options)
			this.id = options['id']
			// 请求数据
			let token = uni.getStorageSync("token")
			api.getNotiById(token, this.id).then(res => {
				if (res.code === 1) {
					this.info = res.data
				} else {
					uni.showModal({
						content: res.errors,
						showCancel: false
					})
				}
			}).catch(err => {
				console.log(err)
			});
		}
	}
</script>

<style lang="less">
	.contain {
		display: flex;
		flex-direction: column;
		align-items: center;

		.title {
			width: 100%;
			height: 100px;
			line-height: 100px;
			background-color: #eee;
			text-align: center;
			font-size: 15px;

		}

		.pubisher {
			width: 100%;
			height: 30px;
			line-height: 30px;
			background-color: #fff;
			// border: #222222 1px solid;
		}

		.button {
			margin: 10px 0;
		}

		.content {
			border: #EEEEEE 5px solid;
			height: calc(100vh - 215px);

		}
	}
</style>
